package com.palfund.handler;

import android.annotation.SuppressLint;
import android.os.Handler;
import android.os.Message;

/**
 * Created by clvc on 2017/7/28.
 * 真正的速度是看不见的 !
 * Today is today , we will go !
 */

public class HandlerFuns {
    private Handler handler;

    @SuppressLint("HandlerLeak")
    public void funZero() {
        handler.sendEmptyMessage(0);
        Handler handler = new Handler();
        handler.post(new Runnable() {
            @Override
            public void run() {

            }
        });
        handler.postAtTime(new Runnable() {
            @Override
            public void run() {

            }
        }, 66666);
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {

            }
        }, 88888);


        this.handler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
            }
        };
    }

    public void funOne() {
        Message message = new Message();
        message.what = 0;
        message.obj = "we will go";
        message.arg1 = 666;
        message.arg2 = 888;
        handler.sendMessage(message);
    }

    public void funTwo() {
        Message message = Message.obtain();
        message.what = 0;
        message.obj = "we will go";
        message.arg1 = 666;
        message.arg2 = 888;
        handler.sendMessageAtTime(message, 6666);
    }

    public void funThree() {
        Message message = handler.obtainMessage();//Message.obtain();
        message.what = 0;
        message.obj = "we will go";
        message.arg1 = 666;
        message.arg2 = 888;
        message.sendToTarget();//调用mHandler.sendMessage(message);
    }

    public void funFour() {
        Message message = Message.obtain();
        message.what = 0;
        message.obj = "we will go";
        message.arg1 = 666;
        message.arg2 = 888;
        message.setTarget(handler);
        message.sendToTarget();
    }
}
